package com.lagou.edu.consumer;

import com.lagou.edu.consumer.service.TPMonitorServiceImpl;
import com.lagou.edu.threadlocal.ThreadPool;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 赵虎
 * @date 2021/1/11 2:04 上午
 */
public class ConsumerApplication {

    /**
     * 定时线程池
     */
    private static final ScheduledThreadPoolExecutor EXECUTOR_SCHEDULED_A = ThreadPool.getScheduledThreadPoolExecutor();
    /**
     * 定时线程池
     */
    private static final ScheduledThreadPoolExecutor EXECUTOR_SCHEDULED_B = ThreadPool.getScheduledThreadPoolExecutor();
    /**
     * 定时线程池
     */
    private static final ScheduledThreadPoolExecutor EXECUTOR_SCHEDULED_C = ThreadPool.getScheduledThreadPoolExecutor();

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        TPMonitorServiceImpl tpMonitorService = applicationContext.getBean(TPMonitorServiceImpl.class);
        EXECUTOR_SCHEDULED_A.scheduleAtFixedRate(tpMonitorService::methodA, 0, 2L, TimeUnit.MILLISECONDS);
        EXECUTOR_SCHEDULED_B.scheduleAtFixedRate(tpMonitorService::methodB, 0, 2L, TimeUnit.MILLISECONDS);
        EXECUTOR_SCHEDULED_C.scheduleAtFixedRate(tpMonitorService::methodC, 0, 2L, TimeUnit.MILLISECONDS);
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.edu.consumer.service")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
